/**
 * 副本 or 地下城
 */
const Router = require('@koa/router');
const { JournalInstance } = require('../db/schemas')

const { Language } = require('../env');
const { genResponse, raw$project } = require('../utils');

const router = new Router({ prefix: '/journal-instance' })

router.get('/', async (ctx) => {
  const results = await JournalInstance.aggregate([
    {
      $project: {
        _id: 0,
        id: 1,
        name: `$name.${Language}`,
        encounters: {
          $map: {
            input: '$encounters',
            as: 'e',
            in: {
              id: '$$e.id',
              name: `$$e.name.${Language}`
            }
          }
        },
        updated_at: 1,
        // raw: '$$ROOT'
      }
    },
    // raw$project,
  ])
  ctx.body = genResponse(true, results)
})
module.exports = router